<!-- 报价表 -->
<template>
    <view class="container">
        <search-header ref="searchHeader" @doFilter="doFilter" @searchFn="searchFn"></search-header>
        <view class="main">
            <mescroll-uni
                v-if="loadOk"
                ref="mescrollRef"
                @init="mescrollInit"
                :height="listHeight"
                :down="downOption"
                @down="downRefresh"
                :up="upOption"
                @up="getData">
                <quotation-item v-for="(item, index) in datas" :key="index" :item="item"></quotation-item>
            </mescroll-uni>
        </view>
    </view>
</template>
<script>
import storage from "@/uni-sub-base/utils/storage.js"
import searchHeader from "@/pages_supplier/components/quotation/search-header.vue"
import quotationItem from "@/pages_supplier/components/quotation/quotation-item.vue"
import { getElementHeight } from "@/uni-sub-base/utils/elementUtil.js"
import { GetProductToSupplierList } from "@/pages_supplier/service/api/supplier.js"
export default {
    components: {
        searchHeader,
        quotationItem,
    },
    data() {
        return {
            listHeight: "500rpx",
            loadOk: false,
            datas: [],
            requestData: {
                searchKey: "",
                startTime: "",
                endTime: "",
                SaleStatus: -1,
            },
            downOption: {
                use: true,
            },
        }
    },
    mounted() {
        this.getListHeight()
    },
    methods: {
        getListHeight() {
            //获取商品高度
            getElementHeight(this, ".main", (e) => {
                this.listHeight = e + "px"
                this.loadOk = true
                setTimeout((e) => {
                    //#ifndef MP
                    this.refresh()
                    //#endif
                }, 300)
            })
        },
        //获取列表数据
        getData(page) {
            let param = this.requestData
            param.pageSize = page.size
            param.pageIndex = page.num

            let path = "?SaleStatus=" + this.requestData.SaleStatus
            GetProductToSupplierList(param, path).then((res) => {
                if (res.State == 1) {
                    this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                    this.datas = this.datas.concat(res.Data)
                } else {
                    this.mescroll.endBySize(0, 0)
                }
            })
        },
        //刷新
        refresh() {
            this.downRefresh()
        },
        //刷新
        downRefresh() {
            this.datas = []
            this.mescroll.resetUpScroll()
        },
        doFilter(e) {
            this.requestData.startTime = e.startDate ? e.startDate + " 00:00:00" : ""
            this.requestData.endTime = e.endDate ? e.endDate + " 23:59:59" : ""
            this.requestData.SaleStatus = e.settlementType
            this.refresh()
        },
        //搜索
        searchFn(searchKey) {
            this.requestData.startTime = ""
            this.requestData.endTime = ""
            this.requestData.SaleStatus = -1
            this.requestData.searchKey = searchKey
            this.$refs.searchHeader.cancelFilter()
            this.refresh()
        },
    },
}
</script>

<style lang="scss"></style>
